<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script>

  function f() {
    alert("hello")
  }

  function f2() {
    var text = document.forms["form"]["a"].value;
      console.log(text);
      if (text == null || text == "" ){
        document.getElementById("pid").innerHTML="不能为空";
    }
  }

  // var a = "abcdefg";
  // var s = a.substr(0,2);
  // var j = a.substring(1,3);
  // console.log(s);
  // console.log(j);



</script>
<body>
<form name="form" method="post" onsubmit="f2()">
    <input type="text" name="fname" required="required"></br>
    <input type="text" name="a"><p id="pid">123</p>
    <input type="submit"  value="提交">
</form>
</body>
</html>